/* 属性管理类型接口模块 */
import httpInstance from '@/utils/http'
/* 数据类型 */
import type {
  respondGetCategory,
  respondGetTrait,
  dataTrait,
} from './traitTypes'
/* 管理所有属性管理接口 */
enum API {
  /* 获取一级分类接口地址 */
  C1_URL = '/admin/product/getCategory1',
  /* 获取二级分类接口地址 */
  C2_URL = '/admin/product/getCategory2/',
  /* 获取三级分类接口地址 */
  C3_URL = '/admin/product/getCategory3/',
  /* 获取分类下已有的属性与属性值 */
  ATTR_URL = '/admin/product/attrInfoList/',
  /* 添加或者修改已有的属性的接口 */
  ADDORUPDATEATTR_URL = '/admin/product/saveAttrInfo',
  /* 删除某一个已有的属性 */
  DELETEATTR_URL = '/admin/product/deleteAttr/',
}

/* 获取一级分类 */
export const getOneCategoryAPI = () => {
  return httpInstance.get<any, respondGetCategory>(API.C1_URL)
}
/* 获取二级分类 */
export const getTwoCategoryAPI = (category1ID: number | string) => {
  return httpInstance.get<any, respondGetCategory>(API.C2_URL + category1ID)
}
/* 获取三级级分类 */
export const getThreeCategoryAPI = (category2ID: number | string) => {
  return httpInstance.get<any, respondGetCategory>(API.C2_URL + category2ID)
}
/* 获取分类下已有的属性与属性值 */
export const getAllTrait = (
  category1ID: number | string,
  category2ID: number | string,
  category3ID: number | string,
) => {
  return httpInstance.get<any, respondGetTrait>(
    API.ATTR_URL + `${category1ID}/${category2ID}/${category3ID}/`,
  )
}
/* 添加属性 */
export const addTraitAPI = (data: dataTrait) => {
  return httpInstance.post<any, any>(API.ADDORUPDATEATTR_URL, data)
}
/* 删除某个已有属性 */
export const deleteAttr = (attrId: number) => {
  return httpInstance.delete<any, any>(API.DELETEATTR_URL + attrId)
}
